package com.smart.util;

import java.util.Map;
import java.util.HashMap;
import java.io.Serializable;

public class Pageable implements Serializable{

	private static final long serialVersionUID = -1486923283258390657L;
	/** 默认页码 */
	private static final int DEFAULT_PAGE_NUMBER = 1;
	/** 默认每页记录数 */
	private static final int DEFAULT_PAGE_SIZE = 10;
	/** 最大每页记录数 */
	private static final int MAX_PAGE_SIZE = 30;
    /** 搜索列表 */
	private Map<String,String> search = new HashMap<String,String>();
	/** 页码 */
	private int page = DEFAULT_PAGE_NUMBER;
	/** 每页记录数 */
	private int limit = DEFAULT_PAGE_SIZE;
	public Pageable(){}
	/**
	 * 初始化一个新创建的Pageable对象
	 * @param page 页码
	 * @param limit 每页记录数
	 **/
	public Pageable(Integer page, Integer limit) {
		this.page = page;
		this.limit = limit;
	}
	/**
	 * 获取页码
	 * @return 页码
	 **/
	public int getPage() {
		return page;
	}
	public int getLimit() {
		return limit;
	}
	public void setLimit(int limit) {
		if(limit > MAX_PAGE_SIZE){
			limit = MAX_PAGE_SIZE;
		}
		if(limit < DEFAULT_PAGE_NUMBER){
			limit = DEFAULT_PAGE_NUMBER;
		}
		this.limit = limit;
	}
	/**
	 * 设置页码
	 * @param pageNumber 页码
	 **/
	public void setPage(int page) {
		if (page < 1) {
			page = DEFAULT_PAGE_NUMBER;
		}
		this.page = page;
	}
	public Map<String, String> getSearch() {
		return search;
	}
	public void setSearch(Map<String,String> search) {
		this.search = search;
	}
}